home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsshade.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  9.2 KB  |  264 lines

  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsshade.h,v 1.3 2000/09/19 19:00:32 lpd Exp $ */
  20. /* Definitions for shading */
  21.  
  22. #ifndef gsshade_INCLUDED
  23. #  define gsshade_INCLUDED
  24.  
  25. #include "gsccolor.h"
  26. #include "gscspace.h"
  27. #include "gsdsrc.h"
  28. #include "gsfunc.h"
  29. #include "gsmatrix.h"
  30. #include "gxfixed.h"
  31.  
  32. /* ---------------- Types and structures ---------------- */
  33.  
  34. /* Define the shading types. */
  35. typedef enum {
  36.     shading_type_Function_based = 1,
  37.     shading_type_Axial = 2,
  38.     shading_type_Radial = 3,
  39.     shading_type_Free_form_Gouraud_triangle = 4,
  40.     shading_type_Lattice_form_Gouraud_triangle = 5,
  41.     shading_type_Coons_patch = 6,
  42.     shading_type_Tensor_product_patch = 7
  43. } gs_shading_type_t;
  44.  
  45. /*
  46.  * Define information common to all shading types.  We separate the private
  47.  * part from the parameters so that clients can create parameter structures
  48.  * without having to know the structure of the implementation.
  49.  */
  50. #define gs_shading_params_common\
  51.   gs_color_space *ColorSpace;\
  52.   gs_client_color *Background;\
  53.   bool have_BBox;\
  54.   gs_rect BBox;\
  55.   bool AntiAlias
  56.  
  57. typedef struct gs_shading_params_s {
  58.     gs_shading_params_common;
  59. } gs_shading_params_t;
  60.  
  61. /* Define the type-specific procedures for shadings. */
  62. #ifndef gs_shading_t_DEFINED
  63. #  define gs_shading_t_DEFINED
  64. typedef struct gs_shading_s gs_shading_t;
  65. #endif
  66. #ifndef gx_device_DEFINED
  67. #  define gx_device_DEFINED
  68. typedef struct gx_device_s gx_device;
  69. #endif
  70.  
  71. /*
  72.  * Fill a user space rectangle.  This will paint every pixel that is in the
  73.  * intersection of the rectangle and the shading's geometry, but it may
  74.  * leave some pixels in the rectangle unpainted, and it may also paint
  75.  * outside the rectangle: the caller is responsible for setting up a
  76.  * clipping device if necessary.
  77.  */
  78. #define SHADING_FILL_RECTANGLE_PROC(proc)\
  79.   int proc(P4(const gs_shading_t *psh, const gs_rect *prect, gx_device *dev,\
  80.           gs_imager_state *pis))
  81. typedef SHADING_FILL_RECTANGLE_PROC((*shading_fill_rectangle_proc_t));
  82. #define gs_shading_fill_rectangle(psh, prect, dev, pis)\
  83.   ((psh)->head.procs.fill_rectangle(psh, prect, dev, pis))
  84.  
  85. /* Define the generic shading structures. */
  86. typedef struct gs_shading_procs_s {
  87.     shading_fill_rectangle_proc_t fill_rectangle;
  88. } gs_shading_procs_t;
  89. typedef struct gs_shading_head_s {
  90.     gs_shading_type_t type;
  91.     gs_shading_procs_t procs;
  92. } gs_shading_head_t;
  93.  
  94. /* Define a generic shading, for use as the target type of pointers. */
  95. struct gs_shading_s {
  96.     gs_shading_head_t head;
  97.     gs_shading_params_t params;
  98. };
  99. #define ShadingType(psh) ((psh)->head.type)
  100. #define private_st_shading()    /* in gsshade.c */\
  101.   gs_private_st_ptrs2(st_shading, gs_shading_t, "gs_shading_t",\
  102.     shading_enum_ptrs, shading_reloc_ptrs,\
  103.     params.ColorSpace, params.Background)
  104.  
  105. /* Define Function-based shading. */
  106. typedef struct gs_shading_Fb_params_s {
  107.     gs_shading_params_common;
  108.     float Domain[4];
  109.     gs_matrix Matrix;
  110.     gs_function_t *Function;
  111. } gs_shading_Fb_params_t;
  112.  
  113. #define private_st_shading_Fb()    /* in gsshade.c */\
  114.   gs_private_st_suffix_add1(st_shading_Fb, gs_shading_Fb_t,\
  115.     "gs_shading_Fb_t", shading_Fb_enum_ptrs, shading_Fb_reloc_ptrs,\
  116.     st_shading, params.Function)
  117.  
  118. /* Define Axial shading. */
  119. typedef struct gs_shading_A_params_s {
  120.     gs_shading_params_common;
  121.     float Coords[4];
  122.     float Domain[2];
  123.     gs_function_t *Function;
  124.     bool Extend[2];
  125. } gs_shading_A_params_t;
  126.  
  127. #define private_st_shading_A()    /* in gsshade.c */\
  128.   gs_private_st_suffix_add1(st_shading_A, gs_shading_A_t,\
  129.     "gs_shading_A_t", shading_A_enum_ptrs, shading_A_reloc_ptrs,\
  130.     st_shading, params.Function)
  131.  
  132. /* Define Radial shading. */
  133. typedef struct gs_shading_R_params_s {
  134.     gs_shading_params_common;
  135.     float Coords[6];
  136.     float Domain[2];
  137.     gs_function_t *Function;
  138.     bool Extend[2];
  139. } gs_shading_R_params_t;
  140.  
  141. #define private_st_shading_R()    /* in gsshade.c */\
  142.   gs_private_st_suffix_add1(st_shading_R, gs_shading_R_t,\
  143.     "gs_shading_R_t", shading_R_enum_ptrs, shading_R_reloc_ptrs,\
  144.     st_shading, params.Function)
  145.  
  146. /* Define common parameters for mesh shading. */
  147. #define gs_shading_mesh_params_common\
  148.   gs_shading_params_common;\
  149.   gs_data_source_t DataSource;\
  150.   int BitsPerCoordinate;\
  151.   int BitsPerComponent;\
  152.   float *Decode;\
  153.   gs_function_t *Function
  154. /* The following are for internal use only. */
  155. typedef struct gs_shading_mesh_params_s {
  156.     gs_shading_mesh_params_common;
  157. } gs_shading_mesh_params_t;
  158. typedef struct gs_shading_mesh_s {
  159.     gs_shading_head_t head;
  160.     gs_shading_mesh_params_t params;
  161. } gs_shading_mesh_t;
  162.  
  163. #define private_st_shading_mesh()    /* in gsshade.c */\
  164.   gs_private_st_suffix_add2(st_shading_mesh, gs_shading_mesh_t,\
  165.     "gs_shading_mesh_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs,\
  166.     st_shading, params.Decode, params.Function)
  167.  
  168. /* Define Free-form Gouraud triangle mesh shading. */
  169. typedef struct gs_shading_FfGt_params_s {
  170.     gs_shading_mesh_params_common;
  171.     int BitsPerFlag;
  172. } gs_shading_FfGt_params_t;
  173.  
  174. #define private_st_shading_FfGt()    /* in gsshade.c */\
  175.   gs_private_st_suffix_add0_local(st_shading_FfGt, gs_shading_FfGt_t,\
  176.     "gs_shading_FfGt_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs,\
  177.     st_shading_mesh)
  178.  
  179. /* Define Lattice-form Gouraud triangle mesh shading. */
  180. typedef struct gs_shading_LfGt_params_s {
  181.     gs_shading_mesh_params_common;
  182.     int VerticesPerRow;
  183. } gs_shading_LfGt_params_t;
  184.  
  185. #define private_st_shading_LfGt()    /* in gsshade.c */\
  186.   gs_private_st_suffix_add0_local(st_shading_LfGt, gs_shading_LfGt_t,\
  187.     "gs_shading_LfGt_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs,\
  188.     st_shading_mesh)
  189.  
  190. /* Define Coons patch mesh shading. */
  191. typedef struct gs_shading_Cp_params_s {
  192.     gs_shading_mesh_params_common;
  193.     int BitsPerFlag;
  194. } gs_shading_Cp_params_t;
  195.  
  196. #define private_st_shading_Cp()    /* in gsshade.c */\
  197.   gs_private_st_suffix_add0_local(st_shading_Cp, gs_shading_Cp_t,\
  198.     "gs_shading_Cp_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs,\
  199.     st_shading_mesh)
  200.  
  201. /* Define Tensor product patch mesh shading. */
  202. typedef struct gs_shading_Tpp_params_s {
  203.     gs_shading_mesh_params_common;
  204.     int BitsPerFlag;
  205. } gs_shading_Tpp_params_t;
  206.  
  207. #define private_st_shading_Tpp()    /* in gsshade.c */\
  208.   gs_private_st_suffix_add0_local(st_shading_Tpp, gs_shading_Tpp_t,\
  209.     "gs_shading_Tpp_t", shading_mesh_enum_ptrs, shading_mesh_reloc_ptrs,\
  210.     st_shading_mesh)
  211.  
  212. /* ---------------- Procedures ---------------- */
  213.  
  214. /* Initialize shading parameters of specific types. */
  215. void gs_shading_Fb_params_init(P1(gs_shading_Fb_params_t * params));
  216. void gs_shading_A_params_init(P1(gs_shading_A_params_t * params));
  217. void gs_shading_R_params_init(P1(gs_shading_R_params_t * params));
  218. void gs_shading_FfGt_params_init(P1(gs_shading_FfGt_params_t * params));
  219. void gs_shading_LfGt_params_init(P1(gs_shading_LfGt_params_t * params));
  220. void gs_shading_Cp_params_init(P1(gs_shading_Cp_params_t * params));
  221. void gs_shading_Tpp_params_init(P1(gs_shading_Tpp_params_t * params));
  222.  
  223. /* Create (initialize) shadings of specific types. */
  224. int gs_shading_Fb_init(P3(gs_shading_t ** ppsh,
  225.               const gs_shading_Fb_params_t * params,
  226.               gs_memory_t * mem));
  227. int gs_shading_A_init(P3(gs_shading_t ** ppsh,
  228.              const gs_shading_A_params_t * params,
  229.              gs_memory_t * mem));
  230. int gs_shading_R_init(P3(gs_shading_t ** ppsh,
  231.              const gs_shading_R_params_t * params,
  232.              gs_memory_t * mem));
  233. int gs_shading_FfGt_init(P3(gs_shading_t ** ppsh,
  234.                 const gs_shading_FfGt_params_t * params,
  235.                 gs_memory_t * mem));
  236. int gs_shading_LfGt_init(P3(gs_shading_t ** ppsh,
  237.                 const gs_shading_LfGt_params_t * params,
  238.                 gs_memory_t * mem));
  239. int gs_shading_Cp_init(P3(gs_shading_t ** ppsh,
  240.               const gs_shading_Cp_params_t * params,
  241.               gs_memory_t * mem));
  242. int gs_shading_Tpp_init(P3(gs_shading_t ** ppsh,
  243.                const gs_shading_Tpp_params_t * params,
  244.                gs_memory_t * mem));
  245.  
  246. /*
  247.  * Fill a path or a (device-space) rectangle with a shading.  Both the path
  248.  * and the rectangle are optional, but at least one must be non-NULL; if
  249.  * both are specified, the filled region is their intersection. This is the
  250.  * only externally accessible procedure for rendering a shading.
  251.  * fill_background indicates whether to fill portions of the path outside
  252.  * the shading's geometry: it is true for filling with a pattern, false for
  253.  * shfill.
  254.  */
  255. #ifndef gx_path_DEFINED
  256. #  define gx_path_DEFINED
  257. typedef struct gx_path_s gx_path;
  258. #endif
  259. int gs_shading_fill_path(P6(const gs_shading_t *psh, /*const*/ gx_path *ppath,
  260.                 const gs_fixed_rect *prect, gx_device *dev,
  261.                 gs_imager_state *pis, bool fill_background));
  262.  
  263. #endif /* gsshade_INCLUDED */
  264.